<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 85167
  Date: 2017/12/10
  Time: 11:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>设备操作记录</title>
    <c:import url="/WEB-INF/page/header.jsp"/>
</head>
<body>
<h4 class="m-t"></h4>
<div class="col-sm-12">
    <!-- Example Toolbar -->
    <div class="example-wrap">
        <div class="panel panel-default">
            <div class="panel-heading"><b>设备操作记录</b></div>
            <div class="panel-body">
                <form id="formSearch" class="form-inline">
                    <input type="hidden" id="bindStatus" value="${bindStatus}">
                    <div class="form-group">
                        <span>imei：</span>
                        <input type="text" class="form-control" id="imei">
                        <span>设备ID：</span>
                        <input type="text" class="form-control" id="devId">
                    </div>
                </form>
            </div>
        </div>
        <div class="example">
            <div class="hidden-xs" id="dataTableToolbar" role="group">
                <div class="pull-right">
                    <button type="button" id="btn_query"
                            class="btn btn-white btn-rounded btn-outline btn-sm "
                            onclick="javascript: $('#dataTable').bootstrapTable('refresh');">
                        <i class="fa fa-search"></i>查询
                    </button>
                </div>
            </div>
            <table id="dataTable" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
            </table>
        </div>
    </div>
    <!-- End Example Toolbar -->
</div>
<c:import url="/WEB-INF/page/footer.jsp"/>
<script type="text/javascript">

    // Example Bootstrap Table Toolbar
    // -------------------------------
    (function () {

        $('#dataTable').bootstrapTable({
            url: base + "/admin/biz/devOpt/list",
            method: "post",
            classes: "table table-hover table-condensed",
            queryParams: function (params) {
                console.log(params.offset);
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,   //页面大小
                    offset: params.offset,  //页码
                    imei: $("#imei").val(),
                    devId: $("#devId").val(),
                };
                return temp;
            },
            toolbar: '#dataTableToolbar',
            pagination: true,
            sidePagination: "server",
            rowStyle: rowStyle,
            columns: [{
                checkbox: true
            }, {
                field: 'devId',
                title: '设备ID'
            }, {
                field: 'imei',
                title: 'imei'
            }, {
                field: 'opt',
                title: '操作'
            }, {
                field: 'createUserName',
                title: '操作人'
            }, {
                field: 'createTime',
                title: '操作时间'
            }]
        });
    })();

    function rowStyle(row, index) {
        if (row.filterFlag == 1) {
            return {classes: "success"}
        }
        var style = "";
        if (row.billTypeId == 0) {
            if (row.remainFlow < 10) {
                style = 'warning';
            }
        } else if (row.billTypeId == 1) {
            if (row.remainTime < 10) {
                style = 'warning';
            }
        }

        return {classes: style}
    }

    function exportData() {
        window.open(base + "/admin/biz/devInfo/export");
    }

    function devInit(id) {
        swal({
            title: "确认要将设备恢复出厂设置吗？(恢复出厂设置后所有数据丢失，请注意，需要执行30秒！)",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/devInit?id=" + id);
        });
    }

    function view(id) {
        openDialogView("查看设备信息", base + "/admin/biz/devInfo/view?id=" + id);
    }

    function filterInit(id, level) {
        swal({
            title: "确认要初始化的第" + level + "级滤芯吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/filterInit?id=" + id + "&level=" + level);
        });
    }

    function start(id) {
        swal({
            title: "您确定要开机吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/start?id=" + id);
        });
    }

    function stop(id) {
        swal({
            title: "您确定要关机吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/stop?id=" + id);
        });
    }

    function force(id) {
        swal({
            title: "您确定要强冲吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/force?id=" + id);
        });
    }

    function unBind(id) {
        swal({
            title: "您确定要解绑吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/unBind?id=" + id);
        });
    }

    function view(id) {
        openDialogView("查看设备信息", base + "/admin/biz/devInfo/view?id=" + id);
    }

    function recharge(id, bilTypeId) {
        var title = "";
        if (bilTypeId == 0) {
            title = "请输入流量(L)"
        } else if (bilTypeId == 1) {
            title = "请输入时长(天)";
        } else {
            swal("买断模式不允许充值");
            return;
        }
        var index = top.layer.prompt({
            title: title,
            formType: 0 //prompt风格，支持0-2
        }, function (pass) {
            top.layer.close(index);
            $.ajax({
                url: base + "/admin/biz/devInfo/recharge/" + id + "/" + pass,
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        swal("保存成功！", "", "success");
                        setTimeout(function () {
                            top.layer.close(index);
                        }, 1000);

                    } else {
                        console.log(data);
                        if (data.msg) {
                            swal("保存失败！", data.msg, "error");
                        } else {
                            swal("保存失败！", data.resultMsg, "error");
                        }

                    }
                }
            })

        });
    }

    function unRecharge(id) {
        layer.config({
            extend: 'extend/layer.ext.js'
        });
        var index = top.layer.prompt({
            title: '输入充值数量',
            formType: 0 //prompt风格，支持0-2
        }, function (pass) {
            $.ajax({
                url: base + "/admin/biz/devInfo/unRecharge/" + id + "/" + pass,
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        swal("保存成功！", "", "success");
                        setTimeout(function () {
                            top.layer.close(index);
                        }, 1000);

                    } else {
                        console.log(data);
                        if (data.msg) {
                            swal("保存失败！", data.msg, "error");
                        } else {
                            swal("保存失败！", data.resultMsg, "error");
                        }

                    }
                }
            })
            top.layer.close(index);
        });
    }

    function devInit(id) {
        swal({
            title: "您确定要恢复出厂吗",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function () {
            doChgStatus(base + "/admin/biz/devInfo/devInit?id=" + id);
        });
    }
</script>
</body>
</html>
